package cn.laixueit;

import cn.laixueit.dao.StudentDaoImpl;
import cn.laixueit.pojo.Student;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Date;

public class Demo {

    @Test
    public void t(){
        /*1 获取xml配置件 得到上下文对象 ,类路径*/
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        /*2 通过上下文对象获取标签中的class的实例*/
        Student student = (Student) context.getBean("student");
        student.show();
    }

    @Test
    public void t2(){
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        /*怎么创建的实例*/
        Student student = context.getBean("student", Student.class);
//        System.out.println(student);
        context.destroy();
    }

    @Test
    public void t3(){
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        /*怎么创建的实例*/
        Student student = context.getBean("student2", Student.class);

    }

    @Test
    public void t4(){
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        /*怎么创建的实例*/
        Student student = context.getBean("studentMethodFactory", Student.class);

    }

    @Test
    public void t5(){
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        /*怎么创建的实例*/
        Student student = context.getBean("student", Student.class);
        System.out.println(student);//地址值

        Student student2 = context.getBean("student", Student.class);
        System.out.println(student2);//地址值

        Student student3 = context.getBean("student", Student.class);
        System.out.println(student3);//地址值

        /*
            默认的是单例模式 ，只有在第一次的时候创建了实例，后续没有在创建了
            张三
              admin @13c27452 1000
              2000 1000 3000
            李四
              root  @13c27452 1000
              1000 -1000  0
            对象少 ,内存，
            多例
        * */

    }

    @Test
    public void t6(){
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        StudentDaoImpl studentDao = context.getBean("studentDao", StudentDaoImpl.class);
        Student student = context.getBean("student", Student.class);
        studentDao.save(student);

    }
}
